<!DOCTYPE html>

<html>

<head>
<meta charset="utf-8">
<title>设置我的密码</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.5/css/layui.css" media="all">
<link rel="stylesheet" type="text/css" href="../../../css/admin.css" />
</head>

<body>

<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header">修改密码</div>
        <div class="layui-card-body" pad15>

          <div class="layui-form" lay-filter="">
            <div class="layui-form-item">
              <label class="layui-form-label">当前密码</label>
              <div class="layui-input-inline">
                <input type="password" name="oldPassword" lay-verify="required" lay-verType="tips" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">新密码</label>
              <div class="layui-input-inline">
                <input type="password" name="password" lay-verify="pass" lay-verType="tips" autocomplete="off" id="LAY_password" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">6到16个字符</div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">确认新密码</label>
              <div class="layui-input-inline">
                <input type="password" name="repassword" lay-verify="repass" lay-verType="tips" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="setmypass">确认修改</button>
              </div>
            </div>
          </div>

        </div>
      </div>
    </div>
  </div>
</div>
</body>
<script src="https://www.layuicdn.com/layui-v2.5.5/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/config.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
layui.use(['form', 'layer'], function() {
  form = layui.form;
  layer = layui.layer;
  form.on('submit(setmypass)', function(data) {
    //当前容器的全部表单字段，名值对形式：{name: value}
    var field=data.field;
    var oldPassword=field.oldPassword;
    var password=field.password;
    var repassword=field.repassword;
    if(!(password===repassword)){
      layer.msg("2次输入密码不一致",{icon: 2,time:2000});
      return false;
    }
    if(oldPassword===password){
      layer.msg("新密码和旧密码不能相同",{icon: 2,time:2000});
      return false;
    }
    $.ajax({
      type: 'post',
      url: projectName + "/user/updatePswd",
      data: field,
      success: function(resp) {
        if(resp.code > -1) {
          layer.msg(resp.msg, { icon: 1, time: 1000 });
        } else {
          layer.msg(resp.msg, { icon: 0, time: 3000 });
          console.log(resp.msg);
        }
      },
      error: function(resp) {
        layer.alert(resp.responseText, { icon: 2, time: 3000 });
      }
    });
    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
  });
})
</script>

</html>